package com.test.spring.beans;

import com.test.spring.collections.Person;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/9/25 15:36
 */
public class Main {
    public static void main(String[] args) {

        /*//创建HelloWorld的一个对象
        HelloWorld helloWorld = new HelloWorld();
        //为name属性赋值
        helloWorld.setName("atguigu");*/

        //1.创建Spring的IOC容器对象
        //ApplicationContext代表IOC容器
        //ClassPathXmlApplicationContext：是ApplicationContext接口的实现类，该实现类从类路径下加载配置文件
        ApplicationContext ctx = new ClassPathXmlApplicationContext("application.xml");

        //2.从IOC容器中获取Bean实例
        //利用id定位到IOC容器中的bean
//        HelloWorld helloWorld = ctx.getBean("helloworld", HelloWorld.class);
        //利用类型返回IOC容器中的bean，要求容器中只有一个该类型的bean
//        HelloWorld helloWorld = ctx.getBean(HelloWorld.class);

        //3.调用hello方法
//        helloWorld.Hello();

        Car car = ctx.getBean("car", Car.class);
        System.out.println(car.toString());

        Car car2 = ctx.getBean("car2", Car.class);
        System.out.println(car2.toString());

        Person person = ctx.getBean("person", Person.class);
        System.out.println(person.toString());

        Person person2 = ctx.getBean("person2", Person.class);
        System.out.println(person2.toString());
    }
}
